<template>
  <div class="center">
    <!-- 头部 -->
    <div class="table_header flex flex_bet flex-wrap">
      <div class="table_button">
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="Refresh"></el-button>
      </div>
      <div class="table_searchs flex felx_align">
        <div class="table_search flex">
          <el-input placeholder="搜索" v-model="searchTable" class="input-with-select" size="small">
            <el-select v-model="select" slot="prepend" placeholder="请选择" class="table_select" style="width:105px">
              <el-option label="代理商/学校" value="1"></el-option>
            </el-select>
            <el-button slot="append" icon="el-icon-search" @click="idnameSearch"></el-button>
          </el-input>
        </div>
      </div>
    </div>
    <el-table stripe style="width: 100%" border fit highlight-current-row ref="tableDataRef" :data="tableData" :key="key">
      <el-table-column min-width="50" align="center" prop="id" label="ID"></el-table-column>
      <el-table-column min-width="50" align="center" prop="name" label="教室名称"></el-table-column>
      <el-table-column min-width="100" align="center" prop="remindText" label="提醒内容"></el-table-column>
      <el-table-column min-width="50" align="center" prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status==='已关闭'" type="danger" @click="changeRemind(scope.row.id, scope.row.status)">{{scope.row.status}}</el-tag>
          <el-tag v-else @click="changeRemind(scope.row.id, scope.row.status)">{{scope.row.status}}</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="paging">
      <el-pagination :current-page.sync="listQuery.startSize" background @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :page-sizes="[10, 50, 100, 200]"
                     layout="total, sizes, prev, pager, next, jumper" :total="total" :page-size="listQuery.pageSize">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  changeRemindStatus,
  queryTeacherMindRoom,
} from "@/api/teacher";

export default {
  data() {
    return {
      key: 1,
      searchTable: "",
      select: "", //搜索条件
      tableData: [],
      total: 0,
      listQuery: {
        startSize: 1,
        pageSize: 10,
        userId: localStorage.getItem("ID"),
      },
      deleteDialogs: {show: false, deleteText: '', deleteId: 0},
    }
  },
  created() {
    this.queryTeacherRemindControl()
  },
  methods: {
    Refresh() {
      this.listQuery = {startSize: 1, pageSize: 10, userId: localStorage.getItem("ID"), name: undefined}
      this.queryTeacherRemindControl()
    },
    //搜索
    idnameSearch() {
      if (!this.select) return this.$message.warning("请先选择查询条件");
      this.listQuery.startSize = 1
      this.listQuery.pageSize = 10
      switch (this.select) {
        case '1':
          this.listQuery.agentName = this.searchTable
          this.queryTeacherRemindControl();
          break;
      }
    },
    queryTeacherRemindControl() {
      queryTeacherMindRoom(this.listQuery).then(res => {
        this.tableData = res.data
        this.total = res.total
      }).catch(err => {
        this.tableData = []
        this.total = 0
      })
    },
    //分页
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.queryTeacherRemindControl()
    },
    handleCurrentChange(val) {
      this.listQuery.startSize = val
      this.queryTeacherRemindControl()
    },
    changeRemind(id, status) {
      let text = status === '提醒中' ? '确认关闭提醒' : '确认重新打开提醒'
      this.$confirm(text, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        changeRemindStatus({
          userId: localStorage.getItem("ID"),
          id: id
        }).then(res => {
          this.$message.success(res.msg)
          this.queryTeacherRemindControl()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    }
  }
}
</script>

<style scoped>

</style>
